use std::vec;

use serde::Serialize;

#[derive(Debug)]
#[derive(Serialize)]
#[derive(Clone)]
pub struct Address {
    pub id: i64,
    pub name: String,
    pub tel: String,
    pub tags: Vec<String>,
}

impl Address {
    pub fn new(id: i64, name: String, tel: String, tags: Vec<String>) -> Address {
        Address {
            id,
            name,
            tel,
            tags,
        }
    }
    pub fn new_from_address_label(address_label: AddressLabel) -> Address {
        let tags = if address_label.label.is_some() {
            vec![address_label.label.unwrap()]   
        } else {
            vec![]
        };
        Address {
            id: address_label.id,
            name: address_label.name,
            tel: address_label.tel,
            tags,
        }
    }
}

/**
 * 存储关联查询的结果
 */
#[derive(Debug)]
#[derive(Clone)]
pub struct AddressLabel {
    pub id: i64,
    pub name: String,
    pub tel: String,
    pub label: Option<String>,
}

impl AddressLabel {
    pub fn new (id: i64, name: String, tel: String, label: Option<String>) -> AddressLabel {
        AddressLabel {
            id,
            name,
            tel,
            label,
        }
    }
}